<template>
    <el-dialog
        @close="handleDialogClose"
        destroy-on-close
        title="设备配置"
        :close-on-click-modal="false"
        :visible="devconfigFlag"
        :append-to-body="true"
        width="720px"
    >
        设备配置
      <!-- <el-form
            v-if="false"
          ref="form"
          :model="form"
          label-width="120px"
          inline
          label-position="right"
          class="form-container"
          :rules="rules"
      >
        <el-form-item label="用户名" prop="username">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="form.password" clearable type="password" show-password autocomplete="new-password"></el-input>
        </el-form-item>
      </el-form>
      <section style="text-align: center;">
        <el-button size="small" @click="handleDialogClose">取消</el-button>
        <el-button size="small" type="primary" :loading="saveLoading" @click="hanldeConfirm">确定</el-button>
      </section> -->
    </el-dialog>
  </template>
  <script>
    import { getDevConfig } from '@/api/sbgl'
    export default {
        data() {
          return {
            rules: {
              username: [
                  {required: true, message: '不能为空', trigger: 'blur'},
                  {max: 24, message: '长度最大 24 个字符', trigger: 'blur' }
              ],
              password: [
                  {required: true, message: '不能为空', trigger: 'blur'},
                  {max: 24, message: '长度最大 24 个字符', trigger: 'blur' }
              ],
            },
            saveLoading:false,
            form: {
              username: "",
              password:"",
            },
          };
        },
        props: {
            devconfigFlag: {
                type: Boolean,
                default: false
            },
            devconfigRow: {
                type: Object,
                defautl: () => {
                    return {}
                }
            }
        },
        computed: {
        },
        watch: {},
        methods: {
            handleDialogClose() {
                // 关闭dialog时，清空表单数据
                this.$refs.form.resetFields();
                this.$emit('update:devconfigFlag',false);
            },
            // 获取设备参数
            getDevConfig(params){
              getDevConfig(params).then((res) => {
                console.log(81, res);
                if (res.code === 200) {
                    // 设置成功
                    this.W.$tips("success", this.i18n.t('Successfully set'));
                    this.parentUpdate();
                }
              }).catch().finally(() => {
                setTimeout(()=>{
                  this.saveLoading=false
                },500)
              })
            },
            hanldeConfirm(){
                // console.log(123, this.form);
                this.$refs.form.validate((valid) => {
                if (valid) {
                    console.log('下一步',this.form);
                    var params=JSON.parse(JSON.stringify(this.form))
                    console.log(135, params);
                    // this.editTableRow = params;
                    // this.$parent.devFlag=false;
                    this.$emit('handleUpdate', params)
                    // 修改成功
                    this.W.$tips("success", this.i18n.t('Successfully saved'));
                    // 更新父页面表格
                    this.handleDialogClose()
                    // this.$parent.submitTopForm()
        
                } else {
                    return false;
                }
                })
            },
        },
        mounted(){
            console.log(123, this.devconfigRow);
            var params = {};
            params.deviceCode = this.devconfigRow.deviceCode;
            console.log(1234, this.devconfigRow);
            params.ip = this.devconfigRow.ip;
            this.getDevConfig(params);

        }
    };
  </script>
  <style scoped lang="scss">
  </style>
  
  